﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Amf4Asmx.IO
{
    public class BigEndianBinaryWriter : BinaryWriter
    {
        public BigEndianBinaryWriter() 
        {
        }

        public BigEndianBinaryWriter(Stream output) : base(output)
        {
        }

        public BigEndianBinaryWriter(Stream output, Encoding encoding)
            : base(output, encoding)
        {
        }

        public override void Write(decimal value)
        {
            throw new NotImplementedException();
        }

        public override void Write(double value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(short value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(int value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(long value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(ushort value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(uint value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }
        public override void Write(ulong value)
        {
            base.Write(Reverse(BitConverter.GetBytes(value)));
        }

        private byte[] Reverse(byte[] p)
        {
            Array.Reverse(p);
            return p;
        }
    }
}
